# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# contributers: Zach Bacon <zachbacon@budgiemedia.rocks>

_realname=SDL2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.12
pkgrel=5
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 2) (mingw-w64)"
arch=('any')
url="https://libsdl.org"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-vulkan")
options=('staticlibs' 'strip')
source=("https://libsdl.org/release/SDL2-${pkgver}.tar.gz"{,.sig}
        001-fix-cmake-target-relocation.patch
        002-fix-link-order.patch
        003-fix-static-library-name.patch
        004-dont-duplicate-libs-in-libs-private.patch)
sha256sums=('349268f695c02efbc9b9148a70b85e58cefbbf704abd3e91be654db7f1e2c863'
            'SKIP'
            '7150ff7c7549d919560eaff44d6f6f76feadbc7da7ce82ca3dcb8e67a91d1daa'
            '4a3906a9b9989dba4967454512921660e0fb275c35263d8ef7d7b34fa5a95e57'
            'a327673cd9d0e60d762860cf8dc96134b6b283314640e5803d918e7f5cd8f9ee'
            '2c3dedf6bd6a10f0dca531c256a85b87db5b12d7558fff4bcea26b9bc73bdc99')
validpgpkeys=('1528635D8053A57F77D1E08630A59377A7763BE6') # Sam Lantinga

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-cmake-target-relocation.patch
  patch -p1 -i ${srcdir}/002-fix-link-order.patch
  patch -p1 -i ${srcdir}/003-fix-static-library-name.patch
  patch -p1 -i ${srcdir}/004-dont-duplicate-libs-in-libs-private.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DVIDEO_VULKAN=ON \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
